<?php /* 	These code was generated using phpCIGen v 0.1.a (21/04/2009)
	#zaqi 		zaqi.smart@gmail.com,http://zenzaqi.blogspot.com, 
    #songbee	mukhlisona@gmail.com
	#CV. Trust Solution, jl. Saronojiwo 19 Surabaya, http://www.ts.co.id
	
	+ Module  		: tbl_s_info Model
	+ Description	: For record model process back-end
	+ Filename 		: c_tbl_s_info.php
 	+ creator 		: 
 	+ Created on 22/Jan/2012 19:08:53
	
*/

class M_tbl_s_info extends CI_Model{
		
		//constructor
		function M_tbl_s_info() {
			parent::__construct();
		}
		
		//function for get list record
		function tbl_s_info_list($filter,$start,$end){
			$query = "SELECT tbl_s_info.*,dvo_id, dvo_name
						FROM tbl_s_info,m_dvo
						WHERE tbl_s_info.info_dvo=m_dvo.dvo_id
						LIMIT 1";
			
			$result = $this->db->query($query);
			$nbrows = $result->num_rows();
			
			if($nbrows>0){
				foreach($result->result() as $row){
					$arr[] = $row;
				}
				$jsonresult = json_encode($arr);
				return '({"total":"'.$nbrows.'","results":'.$jsonresult.'})';
			} else {
				return '({"total":"0", "results":""})';
			}
		}
		
	
		//function for update record
		function tbl_s_info_update($info_id,$info_nama,$info_dvo,$info_alamat,
									$info_notelp,$info_nofax,$info_email,
									$info_website,$info_slogan,$info_logo,$info_logo_tmp,
									$info_icon,$info_background,$info_background_tmp,$info_theme){
			
			/* 
			if($info_logo != ""){
				$info_logo = $info_logo;
			}else{
				$kuery_logo = "SELECT info_logo FROM tbl_s_info WHERE info_id = 1";
				$query_logo = mysql_query($kuery_logo);
				$fetch_logo = mysql_fetch_array($query_logo);
				$info_logo = $fetch_logo['info_logo'];	
			}
			$img_type_arr = explode(".", $info_logo);
			for($i=0; $i<(sizeof($img_type_arr)); $i++){
				$img_type = $img_type_arr[$i];
			}
			$img_file = "logo.".$img_type; 
			$result=move_uploaded_file ($info_logo_tmp,"./assets/images/logo.".$img_type);
			
			if($info_background != ""){
				$info_background = $info_background;
			}else{
				$kuery_back = "SELECT info_background from tbl_s_info WHERE info_id = 1";
				$query_back = mysql_query($kuery_back);
				$fetch_back = mysql_fetch_array($query_back);
				$info_background = $fetch_back['info_background'];
			}
			$img_type_arr_back = explode(".",$info_background);
			for($i=0;$i<(sizeof($img_type_arr_back));$i++){
				$img_type_back=$img_type_arr_back[$i];
			}
			$img_file_back = "desktop.".$img_type_back;
			$result=move_uploaded_file($info_background_tmp,"./assets/wallpapers/desktop.".$img_type_back);
			 */
			$data = array(
				"info_nama"=>$info_nama, 
				"info_alamat"=>$info_alamat, 
				"info_notelp"=>$info_notelp, 
				"info_nofax"=>$info_nofax, 
				"info_email"=>$info_email, 
				"info_website"=>$info_website, 
				"info_slogan"=>$info_slogan, 
				"info_logo"=>$img_file,
				"info_background"=>$img_file_back
			);
			$sql="SELECT dvo_id FROM m_dvo WHERE dvo_name='".$info_dvo."'";
			$rs=mysql_query($sql);
			$num = mysql_num_rows($rs);
			if($num!=0){
				$fetch = mysql_fetch_array($rs);
				$data["info_dvo"]=$fetch['dvo_id'];
			}
			$this->db->update('tbl_s_info', $data);
			return "{success:true}";
		}
				
}
?>